package cn.itrip.vo;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class R<T> {

    public static final String SUCCESS_CODE = "0";
    public static final String SUCCESS = "true";

    public static final String FAIL_CODE = null;
    public static final String FAIL = "false";

    private String errorCode;
    private String msg;
    private String success;
    private T data;

    public static <T> R<T> success(String msg){
        return success(msg,null);
    }

    public static <T> R<T> success(String msg,T data){
        R r = new R();
        r.setErrorCode(SUCCESS_CODE);
        r.setMsg(msg);
        r.setSuccess(SUCCESS);
        r.setData(data);
        return r;
    }

    public static <T> R<T> fail(String msg){
        return fail(msg,null);
    }

    public static <T> R<T> fail(String msg,T data){
        R r = new R();
        r.setErrorCode(FAIL_CODE);
        r.setMsg(msg);
        r.setSuccess(FAIL);
        r.setData(data);
        return r;
    }
}
